package com.pgytesting.secondhandcar.controller.mcpcar;

import com.pgytesting.secondhandcar.model.McpCarDealerInformation;
import com.pgytesting.secondhandcar.service.McpCarDealerInformationService;
import com.pgytesting.secondhandcar.vo.Parameters;
import com.pgytesting.secondhandcar.vo.ResponseMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import javax.validation.Valid;

/**
 * @author : frosty0804@gmail.com
 * @version : v1.0
 * @projectName : secondhandcar
 * @className : McpCarController
 * @description : TODO(销售controller)
 * @date : 2019/8/15 19:51
 */
@RestController
@RequestMapping("/sales/login")
public class LoginMcpCarController {


    @Autowired
    McpCarDealerInformationService mcpCarService;

    /**
     * 销售注册
     *
     * @param mcpCar        注册信息
     * @param bindingResult 参数验证
     * @param session       session
     * @return
     */
    @RequestMapping(value = "/register", method = RequestMethod.POST)
    public ResponseMessage register(@Valid @RequestBody McpCarDealerInformation mcpCar, BindingResult bindingResult, HttpSession session) {
        if (bindingResult.hasErrors()) {
            String msg = bindingResult.getFieldError().getDefaultMessage();
            return ResponseMessage.errorResponse(msg);
        }
        return mcpCarService.insert(mcpCar);
    }


    /**
     * 销售登录
     *
     * @param mcpCar        登录信息
     * @param bindingResult 参数验证
     * @return
     */
    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public ResponseMessage login(@Valid @RequestBody McpCarDealerInformation mcpCar, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            String msg = bindingResult.getFieldError().getDefaultMessage();
            return ResponseMessage.errorResponse(msg);
        }

        return mcpCarService.queryLogin(mcpCar);
    }

}
